package com.dayatang.android.config;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

import com.dayatang.android.Activity.PersonListActivity;
import com.dayatang.android.Activity.PersonLocationActivity;
import com.dayatang.android.Activity.ProjectAdvancedSearchActivity;
import com.dayatang.android.Activity.ProjectSearchActivity;
import com.dayatang.android.Activity.R;
import com.dayatang.android.Activity.ReportsActivity;
import com.dayatang.android.Activity.SubprojectMapActivity;
import com.dayatang.android.Activity.SystemMessageActivity;

public class GridViewConfig {
	
	private static CharSequence[] pmoIndexItemName;
	public static Integer[] pmoIndexImage = {R.drawable.report_icon,R.drawable.system_message_icon,R.drawable.person_icon,R.drawable.sub_map_icon,R.drawable.person_monitor_icon,R.drawable.search_icon,R.drawable.advanced_search_icon};
	public static Integer[] userIndexImage = {R.drawable.system_message_icon,R.drawable.person_icon,R.drawable.sub_map_icon};
	
	private static Context context;
	
	public static List<HashMap<String,Object>> getGridViewList(String type, Context ct) {
		List<HashMap<String,Object>> list = new ArrayList<HashMap<String,Object>>();   
		
		context = ct;
		
		if (type.equals(Config.PMO)) {
			pmoIndexItemName = ct.getResources().getStringArray(R.array.pmo_array);
			for (int i=0; i < pmoIndexItemName.length; i++) {
				HashMap<String,Object> map = new HashMap<String,Object>();
				map.put("ItemImage", pmoIndexImage[i]);
				map.put("ItemName", pmoIndexItemName[i]);
				list.add(map);
			}
		} else if (type.equals(Config.USER)) {
			pmoIndexItemName = ct.getResources().getStringArray(R.array.user_array);
			for (int i=0; i < pmoIndexItemName.length; i++) {
				HashMap<String,Object> map = new HashMap<String,Object>();
				map.put("ItemImage", userIndexImage[i]);
				map.put("ItemName", pmoIndexItemName[i]);
				list.add(map);
			}
		}
		return list;
	}

	public static OnItemClickListener itemClickListener = new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
			switch (GridViewConfig.pmoIndexImage[arg2]) {
				case R.drawable.report_icon:
					context.startActivity(new Intent(context,ReportsActivity.class));
					break;
				case R.drawable.system_message_icon:
					context.startActivity(new Intent(context,SystemMessageActivity.class));
					break;
				case R.drawable.person_icon:
					context.startActivity(new Intent(context,PersonListActivity.class));
					break;
				case R.drawable.sub_map_icon:
					context.startActivity(new Intent(context,SubprojectMapActivity.class));
					break;
				case R.drawable.person_monitor_icon:
					context.startActivity(new Intent(context,PersonLocationActivity.class));
					break;
				case R.drawable.search_icon:
					context.startActivity(new Intent(context,ProjectSearchActivity.class));
					break;
				case R.drawable.advanced_search_icon:
					context.startActivity(new Intent(context,ProjectAdvancedSearchActivity.class));
					break;
			}
		}
	};
	
	public static OnItemClickListener UserItemClickListener = new OnItemClickListener() {
		public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,long arg3) {
			switch (GridViewConfig.userIndexImage[arg2]) {
				case R.drawable.system_message_icon:
					context.startActivity(new Intent(context,SystemMessageActivity.class));
					break;
				case R.drawable.person_icon:
					context.startActivity(new Intent(context,PersonListActivity.class));
					break;
				case R.drawable.sub_map_icon:
					context.startActivity(new Intent(context,SubprojectMapActivity.class));
					break;
			}
		}
	};

}
